package com.thinkgem.jeesite.modules.sys.web;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.sys.entity.Identifier;
import com.thinkgem.jeesite.modules.sys.entity.IdentifierType;
import com.thinkgem.jeesite.modules.sys.service.IdentifierService;
import com.thinkgem.jeesite.modules.sys.service.IdentifierTypeService;


/**
 * 标识管理controller
 * 
 * @author Perry___
 *
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/identifier")
public class IdentifierController extends BaseController {
	
	@Autowired
	private IdentifierService identifierService;
	@Autowired
	private IdentifierTypeService identifierTypeService;
	
	@ModelAttribute("identifier")
	public Identifier get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return identifierService.get(id);
		}else{
			return new Identifier();
		}
	}
	/**
	 * list
	 */
	@RequiresPermissions("sys:identifier:view")
	@RequestMapping(value = {"list", ""})
	public String list(Identifier identifier, IdentifierType identifierType,HttpServletRequest request,HttpServletResponse response, Model model) {
			Page<Identifier> page = identifierService.findPage(new Page<Identifier>(
					request, response), identifier);
			Page<IdentifierType> pageIdentifierType = identifierTypeService.findPage(new Page<IdentifierType>(
					request, response), identifierType);
			model.addAttribute("page", page);
			model.addAttribute("pageIdentifierType", pageIdentifierType);
		return "modules/sys/identifierList";
	}
	
	@RequiresPermissions("sys:identifier:view")
	@RequestMapping(value = "form")
	public String form(Identifier identifier, IdentifierType identifierType,HttpServletRequest request,HttpServletResponse response, Model model){
		return adminPath;
		
	}
	@RequiresPermissions("sys:identifier:view")
	@RequestMapping(value = "save")
	public String save(Identifier identifier, IdentifierType identifierType,HttpServletRequest request,HttpServletResponse response, Model model){
		identifierService.save(identifier);
		return "modules/sys/identifierList";
	}
}
